package cn.lijiajia3515.cairo.system.modules.serial;

import cn.lijiajia3515.cairo.security.oauth2.jwt.CairoJwtPrincipal;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.security.PermitAll;

@RestController
@RequestMapping("/api/serial")
public class SerialApi {
	private final SerialService serialService;

	public SerialApi(SerialService serialService) {
		this.serialService = serialService;
	}

	@GetMapping("/next/{id}")
	@PermitAll
	public long next(@AuthenticationPrincipal CairoJwtPrincipal principal, @PathVariable String id) {
		String client = principal.getClient();
		return serialService.next(client, id);
	}
}
